﻿using PARK.Common.Const;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.Consumer.Entity
{
    /// <summary>
    /// 消费机可用卡片类型
    /// </summary>
    [SugarTable("consum_machine_cardtype")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class ConsumMachineCardtypeEntity
    {
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
        public string Id { get; set; }
        /// <summary>
        /// 消费机Id
        /// </summary>
        [SugarColumn(ColumnName = "MachineId")]
        public string MachineId { get; set; }
        /// <summary>
        /// 消费机编号
        /// </summary>
        [SugarColumn(ColumnName = "MachineNo")]
        public string MachineNo { get; set; }
        /// <summary>
        /// 消费机名称
        /// </summary>
        [SugarColumn(ColumnName = "MachineName")]
        public string MachineName { get; set; }
        /// <summary>
        /// 消费机SN
        /// </summary>
        [SugarColumn(ColumnName = "MachineSerialNum")]
        public string MachineSerialNum { get; set; }
        /// <summary>
        /// 卡类型Id
        /// </summary>
        [SugarColumn(ColumnName = "CardTypeId")]        
        public string CardTypeId { get; set; }
        /// <summary>
        /// 卡类型名称
        /// </summary>
        [SugarColumn(ColumnName = "CardTypeName")]
        public string CardTypeName { get; set; }        
        /// <summary>
        /// 备注
        /// </summary>
        [SugarColumn(ColumnName = "Description")]        
        public string Description { get; set; }        
        /// <summary>
        /// 创建人Id
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserId")]        
        public string CreatorUserId { get; set; }        
        /// <summary>
        /// 创建人姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserName")]        
        public string CreatorUserName { get; set; }        
        /// <summary>
        /// 创建日期
        /// </summary>
        [SugarColumn(ColumnName = "CreatorTime")]        
        public DateTime? CreatorTime { get; set; }      
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "dbDate")]        
        public DateTime? DbDate { get; set; }

        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.Id = YitIdHelper.NextId().ToString();
            this.CreatorTime = DateTime.Now;
            this.DbDate = DateTime.Now;
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
                this.CreatorUserName = CreatorUserName == null ? userName : CreatorUserName;
            }
        }
    }
}